def Prost(n):
    n = int(n)
    g = 2
    while g < n:
        if n % g  == 0:
            return False        
        else:
            g += 1
        if g == n:
            return True


h = input()
if len (h) !=4:
    print(0)
else:
    ma_ch = 0
    d = [h, h[1:3], h[:3], h[1:], h[1], h[0], h[2], h[3], h[2:], h[0:2]]
    for ch in d:
         if int(ch) > ma_ch and Prost(ch):
             ma_ch = int(ch)
    print( ma_ch)


        

            
    
        
        
